#include<bits/stdc++.h>
using namespace std;
#define int long long

const int INF=1e18;
const int Mx=1e5;
const int Maxn=1e5+10;
int N,ans,Mn=INF,ans1;
struct node{
	int a,b,id;
	bool operator <(const node &t)const{
		int x=a+b,y=t.a+t.b;
		return (x^y)?x<y:a<t.a;
	}
}A[Maxn];

inline int read(){
	int ret=0,f=0; char ch=getchar();
	while(!isdigit(ch)){if(ch=='-') f=1; ch=getchar();}
	while(isdigit(ch)) ret=(ret<<1)+(ret<<3)+(ch^48),ch=getchar();
	return f?-ret:ret;
}

int count(int a,int b,int c){
	int ret=A[a].a+A[b].a+A[c].a+A[a].b+A[b].b+A[c].b-min(A[a].b,min(A[b].b,A[c].b));
	return ret;
}

void Solve1(){
	sort(A+1,A+N+1);
	reverse(A+1,A+N+1);
	for(int i=1;i<=3;++i)
		ans+=A[i].a+A[i].b,Mn=min(Mn,A[i].b);
	ans-=Mn;
	for(int i=4;i<=N;++i){
		int x=count(1,2,i),y=count(1,i,3),z=count(i,2,3);
		if(x<y&&x<z&&x<ans) swap(A[3],A[i]),ans=x;
		if(y<x&&y<z&&y<ans) swap(A[2],A[i]),ans=y;
		if(z<x&&z<y&&z<ans) swap(A[1],A[i]),ans=z;
	}
}

void Solve2(){
	sort(A+1,A+N+1); Mn=INF;
	for(int i=1;i<=3;++i)
		ans1+=A[i].a+A[i].b,Mn=min(Mn,A[i].b);
	ans1-=Mn;
	for(int i=4;i<=N;++i){
		int x=count(1,2,i),y=count(1,i,3),z=count(i,2,3);
		if(x<y&&x<z&&x<ans1) swap(A[3],A[i]),ans1=x;
		if(y<x&&y<z&&y<ans1) swap(A[2],A[i]),ans1=y;
		if(z<x&&z<y&&z<ans1) swap(A[1],A[i]),ans1=z;
	}
}

void Solve3(){
	int ret=INF;
	sort(A+1,A+N+1);
	for(int i=1;i<=min(100ll,N);++i) for(int j=i+1;j<=min(100ll,N);++j)
		for(int k=j+1;k<=min(100ll,N);++k){
			int now=A[i].a+A[j].a+A[k].a;
			now+=A[i].b+A[j].b+A[k].b-min(A[i].b,min(A[j].b,A[k].b));
			ret=min(ret,now);
		}
	ans=min(ans,ret);
}

signed main(){
	freopen("boast.in","r",stdin);
	freopen("boast.out","w",stdout);
	N=read();
	for(int i=1;i<=N;++i) A[i].a=read(),A[i].b=read(),A[i].id=i;
	Solve1(); Solve2(); Solve3();
	printf("%lld",min(ans,ans1));
	return 0;
}
/*
7
1 2
1 3
1 7
2 4
3 3
2 6
4 2
*/
